package com.spring.springbootmodel.exception;

import com.spring.springbootmodel.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 作者：黄龙华
 * 功能：自定义异常
 * 日期：2023/11/10 18:17
 */
@ControllerAdvice
public class GlobalException {
    @ExceptionHandler(ServiceException.class)
    @ResponseBody   //将Java对象转成json
    public Result serviceException(ServiceException e){
        return Result.error(e.getCode(),e.getMessage());
    }
}